import type { GroupProcessDefinitionDto, ProcessDefinitionInOrUpReq, PublishProcessDefinitionXmlReq, QueryOneProcessDefinitionReq, QueryProcessDefinitionReq, SaveProcessDefinitionXmlReq } from './type'
import request from '@/utils/request'

enum API {
  GROUPS = '/process/groups/definitions',
  TASK_IMAGE = '/process/definition/image',
}

export function groupsDefinitions() {
  return request<any, GroupProcessDefinitionDto[]>({
    url: API.GROUPS,
    method: 'get',
  })
}

/**
 * 查询任务进度流程图
 */
export function queryTaskImage(processDefinitionId: string) {
  return request<any, string>({
    url: `${API.TASK_IMAGE}/${processDefinitionId}`,
    method: 'get',
  })
}

// 保存流程定义
export function saveProcessDefinition(data: ProcessDefinitionInOrUpReq) {
  return request<any>({
    url: '/pm-process/api/v1/definition/save',
    data,
  })
}

// 分页查询流程定义列表
export function pageProcessDefinition(data: QueryProcessDefinitionReq) {
  return request<any>({
    url: '/pm-process/api/v1/definition/page',
    data,
  })
}

// 查询流程定义 xml
export function getProcessDefinitionXml(data: QueryOneProcessDefinitionReq) {
  return request<any>({
    url: '/pm-process/api/v1/definition/getProcessDefinitionXml',
    data,
  })
}

// 保存流程定义 xml
export function saveProcessDefinitionXml(data: SaveProcessDefinitionXmlReq) {
  return request<any>({
    url: '/pm-process/api/v1/definition/saveProcessDefinitionXml',
    method: 'post',
    data,
  })
}

// 发布流程定义 xml
export function publishProcessDefinition(data: PublishProcessDefinitionXmlReq) {
  return request<any>({
    url: '/pm-process/api/v1/definition/deployProcessDefinitionXml',
    data,
  })
}
